package com.sdy.hospitalguard.embed.keepalive.init;

import com.alibaba.fastjson.JSONObject;
import com.sdy.hospitalguard.biz.constants.MqConstants;
import com.sdy.hospitalguard.embed.keepalive.process.DataProcess;
import com.sdy.mq.service.MqProducerService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

@Component
@Slf4j
public class HttpAccessRecordThread implements Runnable{

    @Autowired
    private MqProducerService mqProducerService;
    @Autowired
    private DataProcess dataProcess;

    /**
     * 终端设备的序列号 or  响应心跳的 deviceCode
     */
    private String serialNo = "210235C4C53203015337";

    public static final BlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();

    @Override
    public void run() {
        // 创建订阅
        try {
            for (;;) {
                String accessRecord = blockingQueue.take();
                /*mqProducerService.send(MqConstants.Tags.TAG_EMBED_SERVER,
                        "/LAPI/V1.0/System/Event/Notification/PersonVerification##hzsdy##" + accessRecord, true);*/
                JSONObject object = JSONObject.parseObject(accessRecord);
                dataProcess.analysis(object);
            }
        }catch (Exception e){
            log.error("", e);
        }
    }
}
